<?php

	class cct_member extends ctl_member
	{
		function _output()
		{
			if($GLOBALS['runtime']['member_lv'])
			{
				$oMemLv = $this->system->loadModel('member/level');
				/* 取得允许下载的会员列表 */
				$aAllowLv = unserialize($this->system->getConf('packets.allowLV'));
				/* 其他会员是否允许查看 */
				$isShow = $this->system->getConf('packets.isShow');
				if ($isShow || in_array($GLOBALS['runtime']['member_lv'],$aAllowLv))
				{
					$this->map[] = array('label'=>'数据包',
										 'items'=>array(
												array(
													'label'=>'数据包下载',
													'link'=>'packet'
												)
										)
									);
				}
				parent::_output();
			}
		}

		function packet($page=1)
		{
			$pageLimit = 10;
			$oPacket = $this->system->loadModel('content/packet');
			$filter = array('ifpub'=>1,'disable'=>'false');
			if ($aPacketList = $oPacket->getList('*', $filter, ($page-1)*$pageLimit, $pageLimit, $counter, array('uptime','desc')))
			{
				$this->pagedata['packetList'] = $aPacketList;
			}
			/* 取得允许下载的会员列表 */
			$aAllowLv = unserialize($this->system->getConf('packets.allowLV'));
			if (in_array($GLOBALS['runtime']['member_lv'],$aAllowLv))
			{
				$this->pagedata['allowDownload'] = true;
			}
			else $this->pagedata['allowDownload'] = false;

			$this->pagedata['pager'] = array(
					'current'=>$page,
					'total'=>ceil($counter/$pageLimit),
					'link'=>$this->system->mkUrl('member','packet',array($tmp = time())),
					'token'=>$tmp);
			$this->_output();
		}

		function packetDownload($packet_id)
		{
			header("Content-type:application/octet-stream;charset=utf-8");
			header("Content-Type: application/force-download");
			$oPacket = $this->system->loadModel('content/packet');
			$row = $oPacket->getFieldById($packet_id,array('packet_href','packet_name'));
			$fileExt = substr($row['packet_href'],strrpos($row['packet_href'],'.'));
			$oCharset = $this->system->loadModel('utility/charset');
			$fileName = $oCharset->utf2local($row['packet_name'].$fileExt,'zh');
			header("Content-Disposition:attachment;filename=".$fileName);
			//$content = $oCharset->utf2local(file_get_contents(BASE_DIR.$row['packet_href']),'zh');
			$content = file_get_contents(BASE_DIR.$row['packet_href']);
			echo $content;
		}
	}

?>